package co.za.itweb.itwebafrica;


import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;




public class GridAdapter extends BaseAdapter{
	 
    private FragmentActivity activity;
    private  String[] data;
    private  LayoutInflater inflater=null;
    
    public  ImageLoader imageLoader; 
    
    public GridAdapter(FragmentActivity a, String[] d) {
        activity = a;
        data=d;
        imageLoader=new ImageLoader(activity.getApplicationContext());
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return data.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
    	 View vi=convertView;
         if(convertView==null)
             vi = inflater.inflate(R.layout.gridbanners, null);
        TextView titletext=(TextView)vi.findViewById(R.id.texttitle);
        ImageButton erasebutton =(ImageButton) vi.findViewById(R.id.erasebutton);
        titletext.setText(data[position]);
        erasebutton.setTag(position);
        erasebutton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        		data[Integer.parseInt(v.getTag().toString())] ="erase" ;
	        		

	    		

	                
	         }
	     });   
       
       
      
        return vi;
    }
}
